package c4.application.transactions.activities;

import java.util.Properties;

import c4.application.transactions.Activity;
import c4.application.transactions.ActivityResult;
import c4.application.transactions.CorporateDatabase;
import c4.application.transactions.Resource;
import c4.common.Constants;

public class LockAccountActivity extends Activity {

	public LockAccountActivity(Properties props) {
		super(props);
	}

	public ActivityResult execute(Resource db, Resource noss) {
		
		CorporateDatabase database = null;
		ActivityResult result= new ActivityResult();
		
		if(!(db instanceof CorporateDatabase)) {
			result.setResult(-1);
		}
		else {
			database = (CorporateDatabase)db;
			String query = "";
			
			query += "INSERT INTO account_locks " +
					 "VALUES ('" + (String)parameters.getProperty(Constants.ACCOUNT_NUMBER) + 
					 "', 'Account currently opened by other user');";
			
			database.execute(query);
			
			result.setResult(1);
		}
		return result;
	}

	 
	public String getType() {
		return Constants.DATABASE;
	}
}
